/**
 * Summary_LSA.java
 *
 * @author Hagen Boehm
 */


package SSF.OS.OSPFv2;


import java.util.*;
import SSF.OS.*;


// ========================= class SSF.OS.OSPFv2.Summary_LSA ============================ //
/**
 * This class implements an OSPF Summary Link State Advertisement. The following from RFC 2328 was
 * not included:
 * 1.) TOS
 * 2.) TOS Metric 
 */

public class Summary_LSA extends ProtocolMessage {

  /** For Type 3 summary-LSAs: The destination network's IP address mask.
   *  For Type 4 summary-LSAs: The value must be zero.
   */
  public int netMask;
  /** The cost of this route. Expressed in the same units as the interface costs in Router_LSA. */
  public int metric;

  // ----------------------------- constructors Summary_LSA ---------------------------- //
  
  /** Type 3 Summary_LSA constructor.
   *  @param mask int value representing the destination network's IP address mask.
   *  @param cost int value representing the cost of this route.
   */
  public Summary_LSA(int mask, int cost) {
    netMask = mask;
    metric = cost;
  }

  /** Type 4 Summary_LSA constructor.
   *  @param cost int value representing the cost of this route.
   */
  public Summary_LSA(int cost) {
    netMask = 0;
    metric = cost;
  }

  // ----------------------------- Summary_LSA.carryPayload ---------------------------- //

  public void carryPayload(ProtocolMessage payload) {
    System.err.println("** Warning: Summary_LSA can't take payload; dropping.");
  }

  // ------------------------------- Summary_LSA.bytecount ---------------------------- //
  /** @return int value indicating the total size (in bytes) of this Summary_LSA body. 
   */
  public int bytecount(){
    return header_bytecount();
  }

  // ---------------------------- Summary_LSA.header_bytecount ------------------------- //
  /** Return the size (in bytes) of this header only, don't include a payload. 
   *  Summary_LSA classes don't have payload.
   *  @return int value indicating the total size (in bytes) of this Summary_LSA body. 
   */
  public int header_bytecount(){
    return (7);
  }

  // -------------------------------- Summary_LSA.copy ---------------------------------- //
  /** Return an exact copy of this data structure. This method is used indirectly by the
   *  Neighbor Data structure to send a copy of a Summary LSA to its associated Neighbor.
   */
  public ProtocolMessage copy() {
    Summary_LSA summaryLSA = new Summary_LSA(netMask, metric);
    return summaryLSA;
  }

  // ------------------------------ Summary_LSA.equals ------------------------------- //
  /** Take a Summary_LSA an compare it to this Summary_LSA. If there is no difference
   *  between them return true else false.
   *  @param test Object referencing a Summary_LSA to compare.
   *  @return boolean value indicating whether the content of the Summary_LSAs are equal.
   */
  public boolean equals(Object test) {
    if (test instanceof Summary_LSA) {
      Summary_LSA testSummaryLSA = (Summary_LSA)test;
      if (testSummaryLSA.metric != metric) return false;
      if (testSummaryLSA.netMask != netMask) return false;
      return true;
    }
    return false;
  }

} // end of class Summary_LSA
